<#setting url_escaping_charset="UTF-8">
<#-- 
MACRO: postItem
INPUT: postUrl
       postTitle 
       postNotes
       postTags
       postCreatedOn
       postUser     
       postLink     
-->
<#macro postItem postId postUrl postTitle postNotes 
        postUser postTags postCreatedOn postLink postInFolders=[] emText=[]>
<#if (postId > 0)>
  <#if folderName?exists && loggedInUser?exists> 
    <#if (loggedInUser.username==folder.user.username)>
      <#local rmbmUrl=gzUrl("/rmbmark?url="+postUrl?url+"&folderName="+folderName
                          +"&owner="+postUser.username+"&redirectToPage="+(toPageHref?if_exists)?url)/>   
    </#if>                          
  </#if> 
  <#local delbmUrl=gzUrl("/delpost?url="+postUrl?url+"&redirectToPage="+(toPageHref?if_exists)?url) />     
  <#local edtbmUrl=gzUrl("/edtpost?url="+postUrl?url+"&redirectToPage="+(toPageHref?if_exists)?url) />
  <#local arcbmUrl=gzUrl("/arcpost?url="+postUrl?url) />
  <#local bmarkId="bmark_"+postId?c />
</#if>
<#local savbmUrl=gzUrl("/post?url="+postUrl?url+"&title="+postTitle?url) />        
<li id="${'p_'+bmarkId}" class="post">   
<div class="post-container">  
<div class="post-title">  
     <@ww.checkbox cssClass="selectBookmark invisible" name="bookmarkId" id="c_"+bmarkId fieldValue=postId?c/>     
     <a id="${bmarkId}" href="${postUrl}" class="previewlink bmark-link" target="_blank">${highlightText(postTitle,emText,"SPAN",["matched_text"])}</a>           
</div>    
  <div class="post-actions">  
  <#nested/>
  <#if loggedInUser?exists> 
    <#if (loggedInUser.username == postUser.username) && (postId > 0)>  
      <a href="${edtbmUrl}" title="edit" class="system-link edit-bmark-link">edit</a>    
    <#else>    
      <a href="${savbmUrl}" title="save" class="system-link save-bmark-link">save</a>
    </#if>   
  </#if>  
  </div>   
</div>
   
    <#assign notesGrp = sliceNotes(postNotes)/>
    <#if (notesGrp?size == 1)>    
      <#assign n = highlightText(notesGrp[0],emText,"SPAN",["matched_text"])/>
      <#if n != "">
       <div class="notes">
         <div class="shrtNotes">${n}</div>
       </div> 
      </#if>
    <#elseif (notesGrp?size == 2)>
      <div class="notes">
         <div class="prvwNotes">${highlightText(notesGrp[0],emText,"SPAN",["matched_text"])} ... 
         <a href="#" title="read more" class="showMoreNotes showOrHideNotes"><img alt="read more" src="${gzUrl("/images/call_out.gif")}"></img></a>
         </div>
         <div class="extNotes invisible">${highlightText(notesGrp[1],emText,"SPAN",["matched_text"])}
         <a href="#" title="show less" class="showLessNotes showOrHideNotes"><img alt="show less" src="${gzUrl("/images/call_in.gif")}"></img></a> 
         </div>       
      </div>          
    </#if>
   
    <div class="meta">
    <div class="info">by <a href="${gzUserUrl(postUser.username)}">${postUser.username}</a> 
  <#if (postTags?size > 0) >
    tagged 
  <#list postTags as tag>    
    <a class="tag" href="${gzUserBmarkArchivesUrl(postUser.username,tag)}">${highlightText(tag,emText,"SPAN",["matched_text"])}</a><#if tag_has_next>, </#if>
  </#list>
  ::
  </#if>
  <#if (postInFolders?size > 0)>
   in folder 
    <#list postInFolders as fldr>
    <#local fldrHref = gzUserFolderUrl(postUser.username,fldr)/>
    <#local fname = gzFormatFolderName(fldr)/>
    <a class="folder f_${bmarkId}" href="${fldrHref}" title="folder: ${fname}">${fname}</a><#if fldr_has_next>, </#if>
    </#list>
   ::
  </#if>
   saved by <a href="${gzLinkUrl(postLink.urlHash)}">${postLink.count}
  <#if (postLink.count > 1)>people <#else> person</#if></a>
   :: ${postCreatedOn?string("EEE, MMM d, ''yy")}
   </div>
   </div>
  </li>      
</#macro>

<#macro checkBookmarkExists bookmarks inFolder="">
<#if (bookmarks?size > 0)>
  <#nested/>
<#else>
<h3>No saved bookmarks here!</h3>
<p>

<#if inFolder != "">
<#local user = inFolder.user/>
  <#if tag?exists>
<h4>Explore bookmarks tagged '${tag}':</h4>  
<ul>
<#local mytaggedHref = gzUserBmarkArchivesUrl(user.username,tag)/>
<li><a href="${mytaggedHref}">by ${user.username} in bookmark archive</a></li>
<#local cmmtagHref = gzUrl('/tag/'+tag?url)/>
<li><a href="${cmmtagHref}">by users in the community</a></li>
</ul>    
  </#if>
<h4>Explore bookmarks saved by ${user.username}:</h4>
<ul>
<#local fldrHref = gzUserFolderUrl(user.username,'')/>
<li><a href="${fldrHref}" title="folders">in other folders</a></li>
<#local arcHref = gzUserBmarkArchivesUrl(user.username)/>
<li><a href="${arcHref}" title="bookmark archive">in bookmark archive</a></li>
</ul>
<#else>
  <#if loggedInUser?exists && (loggedInUser.username == username)>
<h4>Try this:</h4>  
<ul>
<li><a href="${gzUrl('/post')}">Add new bookmark</a></li>  
</ul>
  </#if>
</#if>
<h4>Explore the community:</h4>
<ul>
<#local cmmtyHref = gzUrl('/topusers')/>
<li><a href="${cmmtyHref}" title="top users">top users</a></li>
<#local tagsHref = gzUrl('/tags')/>
<li><a href="${tagsHref}" title="popular tags">popular tags</a></li>
</ul>
</p>

</#if>  
</#macro>

<#function sliceNotes notes>
  <#local nts = notes/> 
  <#local s = notes?replace("</?[a-z]+[^>]*>"," ","irm")/>
  <#if (s?length > 255) || (notes?matches(".*<.*>.*"))>
    <#local shrNotes = ""/>   
    <#local res = s?matches("([\\S]+)","rm")/>
    <#list res as t>     
      <#if (t_index < 30) == true>
        <#local shrNotes = shrNotes + t?groups[1] + " "/> 
      <#else>
        <#break/>
      </#if>    
    </#list>
    <#return [shrNotes+"...",nts]/>
  <#else>
    <#return [nts]/>    
  </#if>
</#function>
